package dns

/*
Copyright 2021-2025 The k8gb Contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
*/

import (
	"context"
	"fmt"

	"github.com/k8gb-io/k8gb/controllers/resolver"

	"sigs.k8s.io/controller-runtime/pkg/client"
)

type ProviderFactory struct {
	config  resolver.Config
	client  client.Client
	context context.Context
}

func NewDNSProviderFactory(context context.Context, client client.Client, config resolver.Config) (f *ProviderFactory, err error) {
	if client == nil {
		err = fmt.Errorf("nil client")
	}
	f = &ProviderFactory{
		context: context,
		config:  config,
		client:  client,
	}
	return
}

func (f *ProviderFactory) Provider() Provider {
	switch f.config.EdgeDNSType {
	case resolver.DNSTypeExternal:
		return NewExternalDNS(f.context, f.client, f.config)
	case resolver.DNSTypeInfoblox:
		ibx := NewInfobloxClient(f.config)
		return NewInfobloxDNS(f.config, ibx)
	}
	return NewEmptyDNS(f.config)
}
